www.gusucode.com > VC++ ICPQ聊天室源程序-源码程序 > VC++ ICPQ聊天室源程序-源码程序/code/ChatRoomSever/InputMsg.cpp

    // InputMsg.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "chatroomserver.h"
#include "ChatServer.h"
#include "InputMsg.h"

extern ChatServer* g_pchatserver; 

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInputMsg

CInputMsg::CInputMsg()
{
}

CInputMsg::~CInputMsg()
{
}


BEGIN_MESSAGE_MAP(CInputMsg, CEdit)
	//{{AFX_MSG_MAP(CInputMsg)
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInputMsg message handlers
void CInputMsg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	char errormsg[30],tmp[DEFAULT_BUFFER_SIZE];
//	wsprintf(msg,"%d:%d",nChar,nFlags);
//	::MessageBox(NULL,msg,"test",MB_OK);

	CEdit::OnChar(nChar,nRepCnt,nFlags);

	if (nChar == 10)					//nChar 10 stand for "Ctrl+Enter" key
	{
	   BUFFER_OBJ *newobj = (BUFFER_OBJ *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BUFFER_OBJ));
		if (newobj == NULL)
		{
			wsprintf(errormsg, "PublicSendBufffer: HeapAlloc failed: %d", GetLastError());
			::MessageBox(NULL,errormsg,"Error",MB_OK);
			return;
		}
		GetWindowText((LPTSTR)newobj->DataBuffer,DEFAULT_BUFFER_SIZE);
		wsprintf(tmp,"[系统消息]%s\n\r",newobj->DataBuffer);
		strcpy(newobj->DataBuffer,tmp);
		g_pchatserver->SendPublicMessage(newobj);
//		this->SetWindowText("\n");
		this->SetSel(0, -1);
		this->ReplaceSel("");
	}
}